home *** CD-ROM | disk | FTP | other *** search
/ The Best of MacTutor - S…e Code for Volumes 1 to 5 / The Best of MacTutor - Source Code for Volume 1-5 (Wayzata Technology)(6031)(1990).bin / Source Code / #48 (Sep 89) / Zoundz Source / MySound.Pas < prev    next >
Pascal/Delphi Source File  |  1989-05-01  |  2KB  |  81 lines

  1. unit MySound;
  2. interface
  3.     uses
  4.         PrintTraps, Sound, MyGlobals;
  5.  
  6.     {creates a 'snd ' resource}
  7.     procedure CreateSndResource (StartSel, EndSel: integer);
  8.  
  9. implementation
  10.  
  11.     procedure CreateSndResource;
  12.         var
  13.             i, j: integer;
  14.             amplong, freqlong: longint;
  15.             lastTimbre: integer;
  16.             theErr: OSErr;
  17.             theSize: integer;
  18.     begin
  19.         lastTimbre := -1;
  20.         if Handle(MySoundHandle) <> nil then
  21.             begin
  22.                 DisposHandle(Handle(MySoundHandle));
  23.                 DisposHandle(MyHandle);
  24.             end;
  25.  
  26.         MySoundHandle := MySoundHdl(NewHandle(sizeof(MySoundRec)));
  27.         with MySoundHandle^^ do
  28.             begin
  29.                 format := 1; {set up header stuff}
  30.                 SynthCount := 1;
  31.                 SynthType := 1;
  32.                 SynthInit := 0;
  33.                 with MyDoc^ do
  34.                     begin
  35.                         j := 0;
  36.                         for i := StartSel to EndSel do
  37.                             begin {get sound commands}
  38.                                 j := j + 1;
  39.                                 if timbre[i] <> lastTimbre then {do we need a timbre command?}
  40.                                     begin
  41.                                         MySounds[j].cmd := timbreCmd;
  42.                                         MySounds[j].param1 := timbre[i];
  43.                                         MySounds[j].param2 := 0;
  44.                                         lastTimbre := timbre[i];
  45.                                         j := j + 1;
  46.                                     end; {of timbre command}
  47.  
  48.                                 if freq[i] = 128 then {is it a rest?}
  49.                                     begin
  50.                                         MySounds[j].cmd := restCmd;
  51.                                         MySounds[j].param1 := dur[i];
  52.                                         MySounds[j].param2 := 0;
  53.                                     end
  54.                                 else {no, regular note}
  55.                                     begin
  56.                                         ampLong := amp[i];
  57.                                         ampLong := BitAnd(BitShift(ampLong, 24), $FF000000);
  58.                                         freqLong := BitAnd(freq[i], $000000FF);
  59.                                         MySounds[j].cmd := noteCmd;
  60.                                         MySounds[j].param1 := dur[i];
  61.                                         MySounds[j].param2 := ampLong + freqLong;
  62.                                     end;
  63.                             end; {of for loop}
  64.                     end; {with MyDoc}
  65.                 j := j + 1;
  66.                 MySounds[j].cmd := noteCmd; {turn off sound}
  67.                 MySounds[j].param1 := 0;
  68.                 MySounds[j].param2 := 0;
  69.                 j := j + 1;
  70.                 MySounds[j].cmd := quietCmd;
  71.                 MySounds[j].param1 := 0;
  72.                 MySounds[j].param2 := 0;
  73.                 CommandCount := j;
  74.             end; { of with MySoundHandle}
  75.         theSize := 12 + (j * 8);
  76.         MyHandle := Handle(MySoundHandle);
  77.         theErr := HandToHand(MyHandle);
  78.         SetHandleSize(MyHandle, Size(theSize));
  79.     end; { of CreateSndResource}
  80.  
  81. end.